<?php

namespace App\Models;

use Illuminate\Database\Eloquent\Factories\HasFactory;
use Illuminate\Database\Eloquent\Model;

class Customer extends BaseModel
{
    use HasFactory;
    protected $table = 'customer';
    // 允许批量操作的字段
    protected $fillable = [
        'customer_name',
        'provinces',
        'city',
        'county',
        'customer_address',
        'contact',
        'contact_phone',
        'remark',
        'is_del',
        'balance',
        'logistics',
        'created_at',
        'updated_at'
    ];

    public function scopeSearch($query,$params)
    {
        if(!empty($params['customer_name'])){
            $query->where('customer_name','like','%'.$params['customer_name'].'%');
        }
        if(!empty($params['provinces'])){
            $query->where('provinces','like','%'.$params['provinces'].'%');
        }
        $query->where('id','>',0);
        $query->where('is_del',2);
        return $query;
    }
}
